package nl.sodeso.cubicex.command.assertion;

import java.util.Map;

import nl.sodeso.cubicex.CubicExBaseTestCase;

import org.cubictest.selenium.custom.IElementContext;

import com.thoughtworks.selenium.Selenium;

/**
 * Replaces the <code>getEval</code> command of SeleniumIDE
 * 
 * @author c.beaujoin
 * @since 0.0.4
 */
public class AssertJavascriptVariable extends CubicExBaseTestCase {

	/**
	 * {@inheritDoc}
	 */
	public void executeTest(final Map<String, String> arguments, final IElementContext context, final Selenium selenium) throws Exception {
		// Retrieve the parameters.
		final String _varName = getArgTarget();
		final String _expectedValue = getArgValue();
		
		//Retrieve Javascript Variable value
		String stringJavascript = "this.browserbot.getCurrentWindow()." + _varName;
		
		String _javascriptVariable = selenium.getEval(stringJavascript);
		
		System.out.print("\nstringJavascript : "+stringJavascript+"\n_javascriptVariable : "+_javascriptVariable);
		
		assertEquals(_javascriptVariable, _expectedValue);			
	}
}

